<!DOCTYPE html>
<html>
<head>

	<script type="text/javascript" src="__PUBLIC__/easyui/jquery.min.js"></script>
	<script type="text/javascript" src="__PUBLIC__/easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="__PUBLIC__/easyui/locale/easyui-lang-zh_CN.js"></script>
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/easyui/themes/gray/easyui.css">
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/easyui/themes/icon.css">
	<script type="text/javascript" src="__PUBLIC__/js/add-tab.js"></script>

</head>
	
<body>

	<table id="tt" class="easyui-datagrid" title="请假管理" style="width:auto;height:auto"
			pageSize="20" pageList="[20,40,80]" data-options="rownumbers:true,singleSelect:true,url:'__URL__/leaveListData',toolbar:'#tb',iconCls:'icon-leavelist'" pagination="true" fitColumns="true" fit="true">
		<thead>
			<tr>
				<th field="process_num" width="80" align="center">流程号</th>
				<th field="process_begin_id" width="80" align="center">请假人</th>
				<th field="process_now_id" width="80" align="center">审批人</th>
				<th field="process_time" width="80" align="center" formatter="formatTime">审批时间</th>
				<th field="process_state" width="80" align="center">状态</th>
			</tr>
		</thead>
	</table>
	<div id="tb" style="padding:5px;height:auto">
		<div style="margin-bottom:5px">
			<a href="javascript:void(0);" src="__APP__/Process/searchDetail" id="searchDetail" class="cs-navi-tab-detail easyui-linkbutton" iconCls="icon-employe-add">请假详情</a>
			<a href="javascript:void(0);" src="__APP__/Process/checkProcess" class="cs-navi-tab-check easyui-linkbutton" id="checkProcess" iconCls="icon-employe-add">审批</a>
		</div>
	</div>

<script type="text/javascript">
	function formatTime(val,row) {     
	 		return new Date(parseInt(val) * 1000).toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ");
	}


    $(function(){
		var i=1;
		$('#tt').datagrid({
			onDblClickRow: function(rowIndex,rowData){
					var $this = $('.cs-navi-tab-detail');
					var href = $this.attr('src') + '?process_type=' + rowData.process_type + '&process_id=' + rowData.process_id + '&process_num=' + rowData.process_num;
					var title = $this.text()+i;
					i++;
					addTab(title, href);
			}
		});
		$('#searchDetail').click(function(){
			var row = $('#tt').datagrid('getSelected');
			if(row){
				var $this = $('.cs-navi-tab-detail');
				var href = $this.attr('src') + '?process_type=' + row.process_type + '&process_id=' + row.process_id + '&process_num=' + row.process_num;
				var title = $this.text()+i;
				i++;
				addTab(title, href);
			}
			else {
            	$.messager.alert('提示', '请选择一条流程', 'info');
            }
		})

		var j=1;
		$('#checkProcess').click(function(){
			var row = $('#tt').datagrid('getSelected');
			if(row){
				if(row.process_state=="正在审批中"){
					var $this = $('.cs-navi-tab-check');
					var href = $this.attr('src') + '?process_type=' + row.process_type + '&process_id=' + row.process_id + '&process_num=' + row.process_num;
					var title = $this.text()+j;
					j++;
					addTab(title, href);	
				}
				else{
					$.messager.alert('提示','该请假已审批过','info');
				}
				
			}
			else {
            	$.messager.alert('提示', '请选择一条流程', 'info');
            }
		})

	})
</script>
</body>
</html>